/**
 * @author 余音袅袅 466375363@qq.com （不想保留author可删除）
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index/index'),
        meta: {
          title: '首页',
          icon: 'home',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/vab',
    component: Layout,
    redirect: 'noRedirect',
    name: 'Vab',
    alwaysShow: true,
    meta: { title: '业务管理', icon: 'box-open' },
    children: [
      {
        path: 'videos',
        name: 'videos_center',
        component: () => import('@/views/audios_view/videos/index'),
        meta: {
          title: '视频管理',
        },
      },
      // {
      //   path: 'test',
      //   name: 'Test',
      //   component: () => import('@/views/audios_view/records/test'),
      //   meta: {
      //     title: '计时器测试',
      //   },
      // },
      {
        path: 'record',
        name: 'Record',
        component: () => import('@/views/audios_view/records/index'),
        meta: { title: '录音管理' },
      },
      {
        path: '/videoDetail',
        name: 'videodetail',
        hidden: true,
        component: () => import('@/views/audios_view/videos/details'),
        meta: { title: '详情页' },
        children: [],
      },
    ],
  },
  {
    path: '/audit',
    component: Layout,
    redirect: 'noRedirect',
    name: 'Audit',
    meta: { title: '审计管理', icon: 'users-cog' },
    children: [
      {
        path: 'videos',
        name: 'videosaudit',
        component: () => import('@/views/audios_view/videosAudit/index'),
        meta: { title: '视频操作审计' },
      },
      // {
      //   path: 'texts',
      //   name: 'textsaudit',
      //   component: () => import('@/views/audios_view/textAudit/index'),
      //   meta: { title: '文本操作审计' },
      // },
      {
        path: 'users',
        name: 'usersaudit',
        component: () => import('@/views/audios_view/userAudit/index'),
        meta: { title: '用户操作审计' },
      },
      {
        path: '/mergeRecord',
        name: 'mergerecord',
        hidden: true,
        component: () => import('@/views/audios_view/records/merge'),
        meta: { title: '录音合成页' },
        children: [],
      },
    ],
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})
//注释的地方是允许路由重复点击，如果你觉得框架路由跳转规范太过严格可选择放开
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}

export function resetRouter() {
  router.matcher = new VueRouter({
    base: publicPath,
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  }).matcher
}

export default router
